package com.moyu.user.controller.sysuser;

import com.moyu.common.core.controller.BaseController;
import com.moyu.common.core.domain.R;
import com.moyu.common.core.domain.TableDataInfo;
import com.moyu.user.domain.sysuser.dto.SysUserSaveDTO;
import com.moyu.user.domain.user.dto.UserDTO;
import com.moyu.user.domain.user.dto.UserQueryDTO;
import com.moyu.user.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统管理员控制层
 *
 * @Author 赵彦博
 * @Date 2024/12/20 17:07
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员接口")
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;

    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "用户ID")
    })
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public R<Void> delete(@PathVariable Long id) {
        return toR(sysUserService.delete(id));
    }

    @GetMapping("/list")
    @Operation(summary = "查询用户列表", description = "根据提供的信息查找用户列表")
    @ApiResponse(responseCode = "1000", description = "成功查询用户列表")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    public TableDataInfo list(UserQueryDTO userQueryDTO) {
        return getTableDataInfo(sysUserService.list(userQueryDTO));
    }

    @PutMapping("/updateStatus")
    @Operation(summary = "更新用户状态", description = "根据提供的信息更新用户状态")
    @ApiResponse(responseCode = "1000", description = "成功查询用户列表")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    public R<Void> updateStatus(@RequestBody UserDTO userDTO) {
        return toR(sysUserService.updateStatus(userDTO));
    }



}
